package cn.talkimages.framework.poi;

import org.apache.poi.ss.usermodel.Cell;

public abstract class CellValueParser {

	public static String getStringValue(Cell cell) {

		String value = null;

		switch (cell.getCellType()) {
		case Cell.CELL_TYPE_STRING: {
			value = cell.getStringCellValue();
			break;
		}
		case Cell.CELL_TYPE_NUMERIC: {
			value = String.valueOf(cell.getNumericCellValue());
			break;
		}
		default:
			throw new UnsupportedOperationException(
					"unsupported execel data type.");
		}

		return value;
	}

	public static double getDoubleValue(Cell cell) {

		double value = 0;

		switch (cell.getCellType()) {
		case Cell.CELL_TYPE_STRING: {
			value = Double.parseDouble(cell.getStringCellValue());
			break;
		}
		case Cell.CELL_TYPE_NUMERIC: {
			value = cell.getNumericCellValue();
			break;
		}
		default:
			throw new UnsupportedOperationException(
					"unsupported execel data type.");
		}

		return value;
	}

	public static int getIntValue(Cell cell) {

		double value = getDoubleValue(cell);

		return (int) value;
	}

	public static long getLongValue(Cell cell) {

		double value = getDoubleValue(cell);

		return (long) value;
	}
}
